/********************************************************************
	created:	2010/01/12
	created:	12:1:2010   16:26
	filename: 	qyInterlocked.h
	author:		Xiong Jiayu
	copyright:  
	purpose:	
*********************************************************************/
#pragma once

#ifndef __QYINTERLOCKED_H__
#define __QYINTERLOCKED_H__

#include "../common/qyCommon.h"

#ifdef _WIN32
#include <windows.h>
/*
===========================================
InterLocked Functions
===========================================
*/
//-----------------------------------------------------------------------
QY_INLINE int qy_InterlockedIncrement(int volatile& var)
{
	return ::InterlockedIncrement((volatile LONG*)&var);
}

//-----------------------------------------------------------------------
QY_INLINE int qy_InterlockedDecrement(int volatile& var)
{
	return ::InterlockedDecrement((volatile LONG*)&var);
}

//-----------------------------------------------------------------------
QY_INLINE void qy_InterlockedAdd(int volatile& var, int add)
{
	::InterlockedExchangeAdd((volatile LONG*)&var, add);
}

//-----------------------------------------------------------------------
QY_INLINE int qy_InterlockedExchange(int volatile* dest, int value)
{
	return ::InterlockedExchange((volatile LONG*)dest, value);
}

//-----------------------------------------------------------------------
QY_INLINE int qy_InterlockedCompareExchange(int volatile* dest, int exchange, int comparand)
{
	return ::InterlockedCompareExchange((volatile LONG*)dest, exchange, comparand);
}
#endif

#endif

